package com.market.cash.utils.helper

import com.market.cash.CashRootApps
import com.market.cash.analyse.AnalyseBuilder
import com.market.cash.analyse.AnalyseUtil
import com.market.cash.configs.CashRootConfigs
import com.market.cash.device.DVSycBuilder
import com.market.cash.device.DVSycManager
import com.market.cash.http.ApiService

/**
 * TODO: Analysis Lib 初始化时机
 */
object CashRootAnalysisHelper {

    /**
     * TODO: APP启动时，初始化一下 analysis lib
     */
    fun initAnalysisLibAtAppLaunch() {
        AnalyseBuilder.product = CashRootConfigs.CASHROOT_APPNAME
        AnalyseBuilder.appVersion = "1"
        AnalyseBuilder.appPckName = CashRootConfigs.CASHROOT_PACKAGENANME

        AnalyseBuilder.aesKey = CashRootConfigs.CASHROOT_AES_KEY
        AnalyseBuilder.aesIv = CashRootConfigs.CASHROOT_AES_IV

        AnalyseBuilder.host = ApiService.CASHROOT_BASE_URL
        AnalyseBuilder.zone = ""
        AnalyseBuilder.pathCommon = ApiService.API_URL.CASHROOT_API_ANALYSIS_URL

        AnalyseBuilder.pathGoogleInstall = ApiService.ANALYSIS_PATH.CASHROOT_ANALYSIS_GOOGLE_INSTALL_PATH
        AnalyseBuilder.pathAdjustInstall = ApiService.ANALYSIS_PATH.CASHROOT_ANALYSIS_ADJUST_INSTALL_PATH
        AnalyseBuilder.pathFacebookInstall = ApiService.ANALYSIS_PATH.CASHROOT_ANALYSIS_FACEBOOK_INSTALL_PATH

        AnalyseUtil.init(CashRootApps.app)
    }

    /**
     * TODO: 成功获取地区转发路径时，初始化一下 analysis lib
     */
    fun initAnalysisLibAtZoneSuccess() {
        AnalyseBuilder.zone = SharedHelper.getCashRootSPString(SharedHelper.CashRoot_SPKEY.CASHROOT_TIMEZONE)
        AnalyseUtil.init(CashRootApps.app)
    }

    /**
     * TODO: 成功登录时，初始化一下 analysis lib
     */
    fun initAnalysisLibAtLoginSuccess() {
        AnalyseBuilder.token = SharedHelper.getCashRootSPString(SharedHelper.CashRoot_SPKEY.CASHROOT_TOKEN)
        AnalyseBuilder.userId = SharedHelper.getCashRootSPString(SharedHelper.CashRoot_SPKEY.CASHROOT_USERID)
        AnalyseUtil.init(CashRootApps.app)
    }
}

/**
 * TODO: Analysis Lib 打点时机
 */
object TestAnalysisAddEvent {

    /**
     * TODO: 在调用登录接口，并成功返回时，如果 type=="REGISTER"，则调用注册事件打点
     */
    fun addRegisterEvent() {
        AnalyseUtil.addRegisterEvent()
    }

    /**
     * TODO: 在调用提交贷款申请接口，并成功返回时，则调用申请事件打点
     */
    fun addApplyEvent() {
        AnalyseUtil.addApplyEvent()
    }
}

/**
 * TODO: Data Lib 初始化时机
 */
object TestDataLibInit {

    /**
     * TODO: 成功获取地区转发路径时，初始化一下 data lib
     */
    fun initDataLibAtZoneSuccess() {
        DVSycBuilder.aesKey = CashRootConfigs.CASHROOT_AES_KEY
        DVSycBuilder.aesIv = CashRootConfigs.CASHROOT_AES_IV

        DVSycBuilder.product = CashRootConfigs.CASHROOT_APPNAME
        DVSycBuilder.appid = CashRootConfigs.CASHROOT_APPNAME

        DVSycBuilder.advertId = AnalyseUtil.getAdId()
        DVSycBuilder.androidId = AnalyseUtil.getAndroidId()

        DVSycBuilder.host = ApiService.CASHROOT_BASE_URL
        DVSycBuilder.zone = SharedHelper.getCashRootSPString(SharedHelper.CashRoot_SPKEY.CASHROOT_TIMEZONE)
        DVSycBuilder.pathCommon = ApiService.API_URL.CASHROOT_API_ANALYSIS_URL
        DVSycBuilder.pathApl = ApiService.ANALYSIS_PATH.CASHROOT_ANALYSIS_APPLIST_PATH
        DVSycBuilder.pathMag = ApiService.ANALYSIS_PATH.CASHROOT_ANALYSIS_SMS_PATH
        DVSycBuilder.pathDie = ApiService.ANALYSIS_PATH.CASHROOT_ANALYSIS_DEVICE_PATH
        DVSycBuilder.pathBty = ApiService.ANALYSIS_PATH.CASHROOT_ANALYSIS_BATTERY_PATH
        DVSycBuilder.pathHdw = ApiService.ANALYSIS_PATH.CASHROOT_ANALYSIS_HARDWAVE_PATH
        DVSycBuilder.pathContat = ApiService.ANALYSIS_PATH.CASHROOT_ANALYSIS_CONTACT_PATH
        DVSycBuilder.pathSto = ApiService.ANALYSIS_PATH.CASHROOT_ANALYSIS_STORGE_PATH
        DVSycBuilder.pathNtw = ApiService.ANALYSIS_PATH.CASHROOT_ANALYSIS_WIFI_PATH
        DVSycBuilder.pathCal = ApiService.ANALYSIS_PATH.CASHROOT_ANALYSIS_CALLLOG_PATH

        DVSycManager.init(CashRootApps.app)
    }
}

/**
 * TODO: Data Lib 调用时机
 */
object TestDataLibInvoke {

    /**
     * TODO: 在首页每次点击申请时（在已登录的前提下），调用一下 data lib 的上报
     */
    fun sycData() {
        val token = SharedHelper.getCashRootSPString(SharedHelper.CashRoot_SPKEY.CASHROOT_TOKEN)
        DVSycBuilder.advertId = AnalyseUtil.getAdId()
        DVSycBuilder.androidId = AnalyseUtil.getAndroidId()

        DVSycManager.syncData(token = token) {
            // 当前业务可忽略这个回调
        }
    }
}